package basic.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class InputStreamDemo {
	public static void main(String[] args) throws Exception {
		FileOutputStream fos = new FileOutputStream("fos.txt");
		fos.write("hello java.basic.io".getBytes());
		fos.write(97);
		fos.write(98);
		fos.write(99);
		fos.write(100);
		fos.write(101);
		fos.close();
		// testAppend();
	}
	//
	public static void test1() throws IOException {

		FileOutputStream fos = new FileOutputStream("c.txt");
		for (int i = 0; i < 10; i++) {
			fos.write(("hello" + i).getBytes());
			fos.write("\r\n".getBytes());
		}
		fos.close();
	}
	public static void testAppend() {

		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream("asd.txt", true);
			for (int i = 0; i < 10; i++) {
				fos.write(("hello" + i).getBytes());
				fos.write("\r\n".getBytes());
			}
		} catch (FileNotFoundException e) {
			System.out.println("�ļ�û���ҵ�!");
		} catch (IOException e) {
			System.out.println("д����ʧ��!");
		} finally {
			if (fos != null) {
				try {
					fos.close();
				} catch (IOException e) {
                  System.out.println("�ļ��ر��쳣!");
				}

			}
		}

	}
}
